package com.taptech.doufu.ui.view.userdetail

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.google.gson.Gson
import com.taptech.doufu.R
import com.taptech.doufu.model.user.ListItem
import com.taptech.doufu.model.user.ReviewBean
import com.taptech.doufu.ui.activity.NovelDetailsActivity
import com.taptech.doufu.ui.activity.weex.SimpleWeexActivity
import com.taptech.doufu.util.DiaobaoUtil
import com.taptech.doufu.util.GsonUtil
import kotlinx.android.synthetic.main.view_user_detail_review.view.*

class UserDetailReviewView(context: Context):LinearLayout(context) {


    init {
        initView()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.view_user_detail_review,null)
        addView(view)
    }


    fun setContentNullData() {
        tvContentNull.visibility = View.VISIBLE
        layMore.visibility = View.GONE
    }

    fun setData(uid:Int,data: ListItem) {
        try {
            val info = GsonUtil.parseJsonWithGson(Gson().toJson(data.data), ReviewBean::class.java)
            setOnClickListener {
                SimpleWeexActivity.startActivity(context,"vue/articalComment/TFArticalCommentDetail.js?id=${info.id}")
            }
            layMore.setOnClickListener {
                val map = HashMap<String, Any>()
                map["uid"] = uid
                map["more_url"] = data.more_url
                SimpleWeexActivity.startActivity(context,"vue/user/TFUserArticalComment.js",map)
            }
            tvUpdateTime.text = DiaobaoUtil.seconds2TimeString(info.add_time)
            tvCount.text = "(${data.count}本)"
            tvNovelName.text = "《${info.novelInfo.topic_title}》"
            tvNovelName.setOnClickListener {
                NovelDetailsActivity.startActivity(context,info.novel_id)
            }
            tvContent.text = info.review
            when (info.star) {
                0 -> {
                    ivStart1.setImageResource(R.drawable.icon_star)
                    ivStart2.setImageResource(R.drawable.icon_star)
                    ivStart3.setImageResource(R.drawable.icon_star)
                    ivStart4.setImageResource(R.drawable.icon_star)
                    ivStart5.setImageResource(R.drawable.icon_star)
                    tvState.text = ""
                }
                1 -> {
                    ivStart1.setImageResource(R.drawable.icon_star_st)
                    ivStart2.setImageResource(R.drawable.icon_star)
                    ivStart3.setImageResource(R.drawable.icon_star)
                    ivStart4.setImageResource(R.drawable.icon_star)
                    ivStart5.setImageResource(R.drawable.icon_star)
                    tvState.text = "重踩"
                }
                2 -> {
                    ivStart1.setImageResource(R.drawable.icon_star_st)
                    ivStart2.setImageResource(R.drawable.icon_star_st)
                    ivStart3.setImageResource(R.drawable.icon_star)
                    ivStart4.setImageResource(R.drawable.icon_star)
                    ivStart5.setImageResource(R.drawable.icon_star)
                    tvState.text = "一般"
                }
                3 -> {
                    ivStart1.setImageResource(R.drawable.icon_star_st)
                    ivStart2.setImageResource(R.drawable.icon_star_st)
                    ivStart3.setImageResource(R.drawable.icon_star_st)
                    ivStart4.setImageResource(R.drawable.icon_star)
                    ivStart5.setImageResource(R.drawable.icon_star)
                    tvState.text = "还行"
                }
                4 -> {
                    ivStart1.setImageResource(R.drawable.icon_star_st)
                    ivStart2.setImageResource(R.drawable.icon_star_st)
                    ivStart3.setImageResource(R.drawable.icon_star_st)
                    ivStart4.setImageResource(R.drawable.icon_star_st)
                    ivStart5.setImageResource(R.drawable.icon_star)
                    tvState.text = "不错"
                }
                5 -> {
                    ivStart1.setImageResource(R.drawable.icon_star_st)
                    ivStart2.setImageResource(R.drawable.icon_star_st)
                    ivStart3.setImageResource(R.drawable.icon_star_st)
                    ivStart4.setImageResource(R.drawable.icon_star_st)
                    ivStart5.setImageResource(R.drawable.icon_star_st)
                    tvState.text = "力荐"
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}
